package boot.dao;

import boot.entity.Product;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.domain.Pageable;

import java.util.List;

public interface ProductRepository extends JpaRepository<Product, Integer> {
    Product findById(int id);

    List<Product> findByNameLike(String name);

    List<Product> findByCountBetween(int count1, int count2);

    List<Product> findByType(String type);

    List<Product> findByPriceBetween(float price, float price2);

    Page<Product> findByNameContains(String name, Pageable page);

    @Query(value = "select p from Product p where (?1 is null or p.name like %?1%) and  (?2 is null or p.price < ?2)")
    List<Product> findWithJPQLByNameAndPrice(String name, float price);
}
